<button class="btn btn-primary" type="button" onclick="addCategory()">新增</button>

<table class="table" id="userListDiv">
    <thead>
    <tr>
        <th>序号</th>
        <th>分类序列号</th>
        <th>产品类别名称</th>
        <th>描述</th>
        <th colspan="2">操作</th>
    </tr>
    </thead>
    <tbody id="tableBody"></tbody>
</table>
<div>
    <ul id="page">分页</ul>
</div>

<script id="categoryListTemplate" type="text/html">
    {{each data value index}}
    <tr>
        <td>{{index+1}}</td>
        <td id="CategoryId">{{value.categoryID}}</td>
        <td>{{value.name}}</td>
        <td>{{value.remark}}</td>
        <td><input value="删除" type="button"  onclick="return del('{{value.categoryID}}')"></td>
        <td><input value="修改" type="button"  onclick="update('{{value.categoryID}}')"></td>
    </tr>
    {{/each}}
</script>

<script>
    $(function () {
        showPage({
            currentPage: 1,
            pageSize: 2,
            url: '/getAllCategory',
            templateId: 'categoryListTemplate',
            contentId: 'tableBody',
            params: {
                id: 1
            }
        })
    })
    function del(obj) {
        if(confirm("确认删除？")){
            Ajax.post(
                "/deleteCategory",
                {categoryId:obj},
                function (result) {
                    show('category/category.html')
                    alert(result.msg)
                }
            )
        }else{
            show('category/category.html')
            return false;
        }

    }
    function update(obj) {
        Ajax.getHtml('category/categoryUpdate.html', function (html) {
            layer.open({
                type: 1,
                title: '修改产品类别',
                area: ['600px'],
                content: html,
                btn: ['确认', '取消'],
                yes: function () {
                    updateCategory()
                },
                btn2: function () {
                    console.log('取消修改产品类别')
                }
            })
        })
        Ajax.post(
            "selectBycategoryID",
            {categoryId:obj},
            function (result) {
                $("#categoryID").val(result.data.categoryID)
                $("#categoryName").val(result.data.name)
                $("#remark").val(result.data.remark)
            }
        )
    }
</script>
